<template>
  <div class="dashboard-container">
    <component :is="currentRole"/>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import adminDashboard from './admin'
import userDashboard from './user'

export default {
  name: 'Dashboard',
  components: { adminDashboard, userDashboard },
  data() {
    return {
      currentRole: 'adminDashboard'
    }
  },
  computed: {
    ...mapGetters([
      'roles'
    ])
  },
  created() {
    // console.log(this.roles)
    const { meta: { resetDashboard } } = this.$route
    if (!this.roles.includes('admin')) {
      // 如果权限没有admin 则登录首页变为user首页
      this.currentRole = 'userDashboard'
    }
    console.log(resetDashboard, 'const { meta: { resetDashboard }} = this.$route')
    if (resetDashboard) {
      this.$router.replace({ path: resetDashboard })
    }
  }
}
</script>
